<template>
	<view class="content wrap">
		<text class="u-demo-block__title">注：身份证正面、驾驶证、行驶证必须上传。其他选填</text>
		<u-form :model="form" ref="uForm"  :rules="rules">
			<!-- <u-form-item label="本人照片" label-width="120">
				<view style="height: 500rpx;" class="u-line-1 u-m-t-10" v-if="!form.darr.sijiphotofileid" @click="uploadimg()">
					<u-image width="500rpx" height="500rpx" src="https://z3.ax1x.com/2021/08/03/ficppn.png"></u-image>
				</view>
				
				<view style="height: 500rpx;" class="u-line-1 u-m-t-10" v-if="form.darr.sijiphotofileid" @click="viewImage(form.darr.sijiphotofileid)">
					<u-image width="500rpx" height="500rpx" :src="imgs(form.darr.sijiphotofileid)"></u-image>
				</view>
			</u-form-item> -->
			
			<u-form-item label="身份证号" label-width="160" left-icon="account" prop="idcard"><u-input v-model="form.darr.idcard" placeholder="请输入身份证号"/></u-form-item>
			
			<u-form-item label="身份证正面" label-width="120" left-icon="star-fill">
				<view style="height: 500rpx;" class="u-line-1 u-m-t-10" v-if="!form.darr.idcarpohtofileid" @click="uploadimg2()">
					<u-image width="500rpx" height="500rpx" src="https://z3.ax1x.com/2021/08/03/ficppn.png"></u-image>
				</view>
				
				<view style="height: 500rpx;" class="u-line-1 u-m-t-10" v-if="form.darr.idcarpohtofileid" @click="viewImage(form.darr.idcarpohtofileid)">
					<u-image width="500rpx" height="500rpx" :src="imgs(form.darr.idcarpohtofileid)"></u-image>
				</view>
			</u-form-item>
			
			<u-form-item label="身份证反面" label-width="120">
				<view style="height: 500rpx;" class="u-line-1 u-m-t-10" v-if="!form.darr.mail" @click="uploadimg3()">
					<u-image width="500rpx" height="500rpx" src="https://z3.ax1x.com/2021/08/03/ficppn.png"></u-image>
				</view>
				
				<view style="height: 500rpx;" class="u-line-1 u-m-t-10" v-if="form.darr.mail" @click="viewImage(form.darr.mail)">
					<u-image width="500rpx" height="500rpx" :src="imgs(form.darr.mail)"></u-image>
				</view>
			</u-form-item>
			
			<u-form-item label="驾驶证号" label-width="160" left-icon="account" prop="drivenumber"><u-input v-model="form.darr.drivenumber" placeholder="请输入驾驶证号"/></u-form-item>
			
			<u-form-item label="驾驶证" label-width="120" left-icon="star-fill">
				<view style="height: 500rpx;" class="u-line-1 u-m-t-10" v-if="!form.darr.jiashizhengphotofileid" @click="uploadimg4()">
					<u-image width="500rpx" height="500rpx" src="https://z3.ax1x.com/2021/08/03/ficppn.png"></u-image>
				</view>
				
				<view style="height: 500rpx;" class="u-line-1 u-m-t-10" v-if="form.darr.jiashizhengphotofileid" @click="viewImage(form.darr.jiashizhengphotofileid)">
					<u-image width="500rpx" height="500rpx" :src="imgs(form.darr.jiashizhengphotofileid)"></u-image>
				</view>
			</u-form-item>
			
			<!-- <u-form-item label="从业证号" label-width="160" left-icon="account" prop="practitionersnumber"><u-input v-model="form.darr.practitionersnumber" placeholder="请输入从业证号"/></u-form-item>
			
			<u-form-item label="从业证" label-width="120">
				<view style="height: 500rpx;" class="u-line-1 u-m-t-10" v-if="!form.darr.congyezhengphotofileid" @click="uploadimg5()">
					<u-image width="500rpx" height="500rpx" src="https://z3.ax1x.com/2021/08/03/ficppn.png"></u-image>
				</view>
				
				<view style="height: 500rpx;" class="u-line-1 u-m-t-10" v-if="form.darr.congyezhengphotofileid" @click="viewImage(form.darr.congyezhengphotofileid)">
					<u-image width="500rpx" height="500rpx" :src="imgs(form.darr.congyezhengphotofileid)"></u-image>
				</view>
			</u-form-item> -->
			
			<!-- <u-form-item label="车辆照片" label-width="120">
				<view style="height: 500rpx;" class="u-line-1 u-m-t-10" v-if="!form.carr.carphotofileid" @click="uploadimg6()">
					<u-image width="500rpx" height="500rpx" src="https://z3.ax1x.com/2021/08/03/ficppn.png"></u-image>
				</view>
				
				<view style="height: 500rpx;" class="u-line-1 u-m-t-10" v-if="form.carr.carphotofileid" @click="viewImage(form.carr.carphotofileid)">
					<u-image width="500rpx" height="500rpx" :src="imgs(form.carr.carphotofileid)"></u-image>
				</view>
			</u-form-item> -->
			
			<u-form-item label="行驶证号" label-width="160" left-icon="account" prop="xingshizhenghao"><u-input v-model="form.carr.xingshizhenghao" placeholder="请输入行驶证号"/></u-form-item>
			
			<u-form-item label="行驶证" label-width="120" left-icon="star-fill">
				<view style="height: 500rpx;" class="u-line-1 u-m-t-10" v-if="!form.carr.xingshizhengfileid" @click="uploadimg7()">
					<u-image width="500rpx" height="500rpx" src="https://z3.ax1x.com/2021/08/03/ficppn.png"></u-image>
				</view>
				
				<view style="height: 500rpx;" class="u-line-1 u-m-t-10" v-if="form.carr.xingshizhengfileid" @click="viewImage(form.carr.xingshizhengfileid)">
					<u-image width="500rpx" height="500rpx" :src="imgs(form.carr.xingshizhengfileid)"></u-image>
				</view>
			</u-form-item>
			
			<!-- <u-form-item label="运营许可证号" label-width="160" left-icon="account" prop="xukezhenghao"><u-input v-model="form.carr.xukezhenghao" placeholder="请输入许可证号"/></u-form-item>
			
			<u-form-item label="运营许可证" label-width="120">
				<view style="height: 500rpx;" class="u-line-1 u-m-t-10" v-if="!form.carr.xukezhengfileid" @click="uploadimg8()">
					<u-image width="500rpx" height="500rpx" src="https://z3.ax1x.com/2021/08/03/ficppn.png"></u-image>
				</view>
				
				<view style="height: 500rpx;" class="u-line-1 u-m-t-10" v-if="form.carr.xukezhengfileid" @click="viewImage(form.carr.xukezhengfileid)">
					<u-image width="500rpx" height="500rpx" :src="imgs(form.carr.xukezhengfileid)"></u-image>
				</view>
			</u-form-item> -->
			
			<!-- <u-form-item label="保险合同号" label-width="160" left-icon="account" prop="baoxianhetonghao"><u-input v-model="form.carr.baoxianhetonghao" placeholder="请输入保险合同号"/></u-form-item>
			
			<u-form-item label="保险合同" label-width="120">
				<view style="height: 500rpx;" class="u-line-1 u-m-t-10" v-if="!form.carr.baoxianhetongfileid" @click="uploadimg9()">
					<u-image width="500rpx" height="500rpx" src="https://z3.ax1x.com/2021/08/03/ficppn.png"></u-image>
				</view>
				
				<view style="height: 500rpx;" class="u-line-1 u-m-t-10" v-if="form.carr.baoxianhetongfileid" @click="viewImage(form.carr.baoxianhetongfileid)">
					<u-image width="500rpx" height="500rpx" :src="imgs(form.carr.baoxianhetongfileid)"></u-image>
				</view>
			</u-form-item> -->
			
		</u-form>
		<u-button @click="submit">提交</u-button>
		<view>
			<u-toast ref="uToast" />
		</view>
	</view>
</template>

<script>
	import config from '../../../config.js'
	export default {
		data() {
			return {
				form:{
					darr:{},
					carr:{}
				},
			};
		},
		onLoad() {
			this.refresh()
		},
		methods:{
			refresh(){
				this.$http.post('/rest/driverAndCar/findDriver',{//查询我的信息
				},{
					params: {},
					header: {
						'Authorization' :uni.getStorageSync('token'),
					}
				}).then(res => {
					this.form.darr = res.data.data
				})
				
				this.$http.post('/rest/driverAndCar/findCar',{//查询我的车辆
				},{
					params: {},
					header: {
						'Authorization' :uni.getStorageSync('token'),
					}
				}).then(res => {
					this.form.carr = res.data.data
				})
			},
			uploadimg(){
				uni.chooseImage({
					count: 1, //默认9
					success: res1 => {
						uni.uploadFile({
							url: config.root + '/rest/driverAndCar/uploadsnew', // 文件上传路径
							filePath: res1.tempFilePaths[0],
							name: 'file',
							header: {
								'Authorization' :uni.getStorageSync('token'),
							},
							formData: {id:this.form.darr.id},
							success: res => {
								let data = JSON.parse(res.data);
								if(data.code == 200) {
									uni.showToast({
										title: '上传成功',
										duration: 2000
									});
									setTimeout(() => {
										this.refresh()
									}, 500)
								} else {
									uni.showToast({
										title: data.message,
										duration: 2000,
										icon:'none',
									});
								}
							}
						})
					}
				})
			},
			uploadimg2(){
				uni.chooseImage({
					count: 1, //默认9
					success: res1 => {
						uni.uploadFile({
							url: config.root + '/rest/driverAndCar/uploadsnew2', // 文件上传路径
							filePath: res1.tempFilePaths[0],
							name: 'file',
							header: {
								'Authorization' :uni.getStorageSync('token'),
							},
							formData: {id:this.form.darr.id},
							success: res => {
								let data = JSON.parse(res.data);
								if(data.code == 200) {
									uni.showToast({
										title: '上传成功',
										duration: 2000
									});
									setTimeout(() => {
										this.refresh()
									}, 500)
								} else {
									uni.showToast({
										title: data.message,
										duration: 2000,
										icon:'none',
									});
								}
							}
						})
					}
				})
			},
			uploadimg3(){
				uni.chooseImage({
					count: 1, //默认9
					success: res1 => {
						uni.uploadFile({
							url: config.root + '/rest/driverAndCar/uploadsnew3', // 文件上传路径
							filePath: res1.tempFilePaths[0],
							name: 'file',
							header: {
								'Authorization' :uni.getStorageSync('token'),
							},
							formData: {id:this.form.darr.id},
							success: res => {
								let data = JSON.parse(res.data);
								if(data.code == 200) {
									uni.showToast({
										title: '上传成功',
										duration: 2000
									});
									setTimeout(() => {
										this.refresh()
									}, 500)
								} else {
									uni.showToast({
										title: data.message,
										duration: 2000,
										icon:'none',
									});
								}
							}
						})
					}
				})
			},
			uploadimg4(){
				uni.chooseImage({
					count: 1, //默认9
					success: res1 => {
						uni.uploadFile({
							url: config.root + '/rest/driverAndCar/uploadsnew4', // 文件上传路径
							filePath: res1.tempFilePaths[0],
							name: 'file',
							header: {
								'Authorization' :uni.getStorageSync('token'),
							},
							formData: {id:this.form.darr.id},
							success: res => {
								let data = JSON.parse(res.data);
								if(data.code == 200) {
									uni.showToast({
										title: '上传成功',
										duration: 2000
									});
									setTimeout(() => {
										this.refresh()
									}, 500)
								} else {
									uni.showToast({
										title: data.message,
										duration: 2000,
										icon:'none',
									});
								}
							}
						})
					}
				})
			},
			uploadimg5(){
				uni.chooseImage({
					count: 1, //默认9
					success: res1 => {
						uni.uploadFile({
							url: config.root + '/rest/driverAndCar/uploadsnew5', // 文件上传路径
							filePath: res1.tempFilePaths[0],
							name: 'file',
							header: {
								'Authorization' :uni.getStorageSync('token'),
							},
							formData: {id:this.form.darr.id},
							success: res => {
								let data = JSON.parse(res.data);
								if(data.code == 200) {
									uni.showToast({
										title: '上传成功',
										duration: 2000
									});
									setTimeout(() => {
										this.refresh()
									}, 500)
								} else {
									uni.showToast({
										title: data.message,
										duration: 2000,
										icon:'none',
									});
								}
							}
						})
					}
				})
			},
			uploadimg6(){
				uni.chooseImage({
					count: 1, //默认9
					success: res1 => {
						uni.uploadFile({
							url: config.root + '/rest/driverAndCar/uploadsnew6', // 文件上传路径
							filePath: res1.tempFilePaths[0],
							name: 'file',
							header: {
								'Authorization' :uni.getStorageSync('token'),
							},
							formData: {id:this.form.carr.id},
							success: res => {
								let data = JSON.parse(res.data);
								if(data.code == 200) {
									uni.showToast({
										title: '上传成功',
										duration: 2000
									});
									setTimeout(() => {
										this.refresh()
									}, 500)
								} else {
									uni.showToast({
										title: data.message,
										duration: 2000,
										icon:'none',
									});
								}
							}
						})
					}
				})
			},
			uploadimg7(){
				uni.chooseImage({
					count: 1, //默认9
					success: res1 => {
						uni.uploadFile({
							url: config.root + '/rest/driverAndCar/uploadsnew7', // 文件上传路径
							filePath: res1.tempFilePaths[0],
							name: 'file',
							header: {
								'Authorization' :uni.getStorageSync('token'),
							},
							formData: {id:this.form.carr.id},
							success: res => {
								let data = JSON.parse(res.data);
								if(data.code == 200) {
									uni.showToast({
										title: '上传成功',
										duration: 2000
									});
									setTimeout(() => {
										this.refresh()
									}, 500)
								} else {
									uni.showToast({
										title: data.message,
										duration: 2000,
										icon:'none',
									});
								}
							}
						})
					}
				})
			},
			uploadimg8(){
				uni.chooseImage({
					count: 1, //默认9
					success: res1 => {
						uni.uploadFile({
							url: config.root + '/rest/driverAndCar/uploadsnew8', // 文件上传路径
							filePath: res1.tempFilePaths[0],
							name: 'file',
							header: {
								'Authorization' :uni.getStorageSync('token'),
							},
							formData: {id:this.form.carr.id},
							success: res => {
								let data = JSON.parse(res.data);
								if(data.code == 200) {
									uni.showToast({
										title: '上传成功',
										duration: 2000
									});
									setTimeout(() => {
										this.refresh()
									}, 500)
								} else {
									uni.showToast({
										title: data.message,
										duration: 2000,
										icon:'none',
									});
								}
							}
						})
					}
				})
			},
			uploadimg9(){
				uni.chooseImage({
					count: 1, //默认9
					success: res1 => {
						uni.uploadFile({
							url: config.root + '/rest/driverAndCar/uploadsnew9', // 文件上传路径
							filePath: res1.tempFilePaths[0],
							name: 'file',
							header: {
								'Authorization' :uni.getStorageSync('token'),
							},
							formData: {id:this.form.carr.id},
							success: res => {
								let data = JSON.parse(res.data);
								if(data.code == 200) {
									uni.showToast({
										title: '上传成功',
										duration: 2000
									});
									setTimeout(() => {
										this.refresh()
									}, 500)
								} else {
									uni.showToast({
										title: data.message,
										duration: 2000,
										icon:'none',
									});
								}
							}
						})
					}
				})
			},
			imgs(fileId){
				return config.root + 'system/previewa/' + fileId
			},
			viewImage(fileId) {
				let arr = []
				let img = config.root + 'system/previewa/' + fileId
				arr.push(img)
				uni.previewImage({
					urls: arr,
				});
			},
			submit() {
				let updated = {}
				updated.id = this.form.darr.id
				updated.idcard = this.form.darr.idcard
				updated.drivenumber = this.form.darr.drivenumber
				updated.practitionersnumber = this.form.darr.practitionersnumber
				let updatec = {}
				updatec.id = this.form.carr.id
				updatec.xingshizhenghao = this.form.carr.xingshizhenghao
				updatec.xukezhenghao = this.form.carr.xukezhenghao
				updatec.baoxianhetonghao = this.form.carr.baoxianhetonghao
				this.$refs.uForm.validate(valid => {
					if (valid) {
						console.log('验证通过');
						uni.showLoading({
							title: '正在提交'
						})
						this.$http.post('/rest/driverAndCar/updateDriver',{
						},{
							params: updated,
							header: {
								'Authorization' :uni.getStorageSync('token'),
							}
						}).then(res => {
							uni.hideLoading()
							if(res.data.code == 200) {
							} else {
								this.$refs.uToast.show({
									title: res.data.message,
									type: 'error'
								})
							}
						})
						this.$http.post('/rest/driverAndCar/updatecar',{
						},{
							params: updatec,
							header: {
								'Authorization' :uni.getStorageSync('token'),
							}
						}).then(res => {
							uni.hideLoading()
							if(res.data.code == 200) {
								this.$refs.uToast.show({
									title: '更新成功',
									type: 'success'
								})
							} else {
								this.$refs.uToast.show({
									title: res.data.message,
									type: 'error'
								})
							}
						})
					} else {
						console.log('验证失败');
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	page{
			background-color: #ffffff;
	}
	
	.wrap {
		padding: 30rpx;
	}
</style>
